<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-config-add" name="form-config-add" enctype="multipart/form-data">
        <div class="form-group">
            <label class="col-sm-3 control-label">文件：</label>
            <div class="col-sm-6">
                <input name="file" onchange="change()" id="file" class="form-control" type="file">
                <!--<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据-->
                <!--&nbsp;	-->
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 预览</a>
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
                <font color="red" class="pull-left mt10">
                    提示：仅允许导入“xls”或“xlsx”格式文件！
                </font>
            </div>
        </div>

        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">文件：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<input name="file" onchange="change()" id="file" class="form-control" type="file">-->
            <!--</div>-->
        <!--</div>-->

        <div class="form-group" id="size" style="display: none">
            <label class="col-sm-3 control-label" for="FileSize">大小：</label>
            <div class="col-sm-8">
                <input class="form-control" id="FileSize" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" rows="7" name="descr" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="form-control-static col-sm-offset-9">
                <button type="submit" class="btn btn-primary">提交</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = "/file"
    var filemaxsize = 10485760;//10485760=50Mb
    function change() {
        $("#size").show();
        var fileSize = document.getElementById("file").files[0].size;
        var size = (fileSize / 1024 / 1024).toFixed(2) + "MB";
        if (fileSize > filemaxsize) {
            $("#FileSize").val(size).css("border-color", "red");
        } else {
            $("#FileSize").val(size);
        }
    }

    $("#form-config-add").validate({
        rules: {
            file: {
                required: true,
            },
            descr:{
                maxlength:200,
            }
        },
        submitHandler: function (form) {
            var fileSize = document.getElementById("file").files[0].size;

            if (fileSize > filemaxsize) {
                $.modal.alertError('附件大小不能大于' + filemaxsize / 1024 + 'M！\r\n');
                return false;
            }


            var key = layer.msg('正在上传...', {
                icon: 16
                , shade: 0.1
                , time: 60000
            });


            var formData = new FormData(document.getElementById("form-config-add"));//表单id
            $.ajax({
                url: prefix + '/addSave',
                type: 'POST',
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    $.operate.saveSuccess(result);
                },
                error: function () {
                    $.modal.alertError("系统错误");
                }
            });

        }
    });
</script>
</body>
</html>
